package com.db.williamchart.animation;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;

import com.db.williamchart.data.DataPoint;

import java.util.List;

public class DefaultAnimation extends ChartAnimation<DataPoint> {
    @Override
    public ChartAnimation<DataPoint> animateFrom(float startPosition, List<DataPoint> entries, final AnimateFromCallback callback) {
        // Entries animators
        for (DataPoint dataPoint : entries) {
            ObjectAnimator eAnimator =
                    ObjectAnimator.ofFloat(
                            dataPoint,
                            "screenPositionY",
                            startPosition,
                            dataPoint.getScreenPositionY());
            eAnimator.setDuration(duration);
            eAnimator.setInterpolator(interpolator);
            eAnimator.start();
        }

        // Global animator
        ValueAnimator animator = ValueAnimator.ofInt(0, 1);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                callback.callback();
            }
        });
        animator.setDuration(duration);
        animator.setInterpolator(interpolator);
        animator.start();

        return this;
    }
}
